<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>机构信息</title>


    <!-- Expand styles -->
    <link href="../css/app/app.css" rel="stylesheet">
    <link href="../css/app/default.css" rel="stylesheet">
    <link href="../css/mui/mui.css" rel="stylesheet">
    <link href="../css/mui/mui.picker.min.css" rel="stylesheet" />

</head>

<body>

    <!-- header -->
    <div class='margin-b-60 info-diffbox'>
        <div class="display-flex justify-content-between align-items-center details-box" onclick="selectImg(0)">
            <span>机构logo</span>
            <div class="display-flex justify-content-between align-items-center">
                <img class="peixun-logo" id="headPortrait" src="../img/headimg.png" imgId=""/>
                <img class="sele-icon" src="../img/next.png" />
            </div>
        </div>
        <div class="display-flex justify-content-between align-items-center details-box">
            <span>用户名</span>
            <span id="mobilePhone"></span>
        </div>
        <div class="display-flex justify-content-between align-items-center details-box">
            <span>成立时间</span>
            <span id="establishTime"></span>
        </div>
        <div class="display-flex justify-content-between align-items-center info-box" onclick="selectTrainType()">
            <span class="leftspan">擅长培训类型</span>
            <div class="display-flex justify-content-between align-items-center">
                <span id="serviceTypeNames"></span>
                <img class="sele-icon" src="../img/next.png" />
            </div>

        </div>
        <div class="display-flex justify-content-between align-items-center info-box" onclick="showAddress()">
            <span class="leftspan">地址</span>
            <div class="display-flex justify-content-between align-items-center">
                <span id="address"></span>
                <img class="sele-icon" src="../img/next.png" />
            </div>
        </div>
        <div class="list-group patient-list margin-b-i10">
            <div class="list-cell text-cell list-cell">
                <div class="web-box1 list-left">详细地址</div>
                <div class="web-box2 nk-s text-right list-right"><input type="text" placeholder="请输入详细地址" id="addressDetail">
                </div>
            </div>
        </div>
        
        <div class="widget-default widget-body margin-b-10">
            <div class="web-box1 list-left font-15 black">简介</div>
            <div class="list-right">
                <textarea class="no-margin info-textarea" type="text" placeholder="简介描述" id="introduction"></textarea>
            </div>
        </div>
        <div class="widget-default widget-body">
            <div class="web-box1 list-left padding-b-10 font-15 black">资质证书<span class="font-13 gray">(最多可上传5张)</span>
            </div>
            <div class="list-right">
                <img class="ser-img" src="../img/add-img.png" alt="" onclick="selectImg(1)" id="selectCredentialImg">
            </div>

        </div>

    </div>

    <div class="save-btn  hobby-footer1">
        <button type="button" class="mui-btn mui-btn-primary mui-btn-block bc-head" onclick="save()">保存</button>
    </div>

    <script src="../js/dsbridge.js"></script>
    <script src="../js/jquery.js"></script>
    <script src="../js/mui/mui.js"></script>
    <script src="../js/mui/mui.picker.min.js"></script>
    <script src="../js/layer.js"></script>
    <script src="../js/city.data-3.js"></script>
    <script src="../js/app/app-base.js"></script>
    <script src="../js/app/app-url.js"></script>
    <script src="../js/app/app-ajax.js"></script>
    <script>
        //图片类型 0-机构logo 1-资质证书
        var imgType = 0;
        //图片最大数量
        var maxImgNum = 5;
        //擅长培训类型code
        var serviceTypeCodeList = new Array();
        //擅长培训类型名称
        var serviceTypeNameList = new Array(); 
        //省code
        var provinceCode = "";
        //市code
        var cityCode = "";
        //区code
        var countyCode = "";
        //地址选择
        var pickerAddress = new mui.PopPicker({
            layer: 3
        });
        $(document).ready(function(){
            //获取机构信息
            getDetail();
            pickerAddress.setData(cityData3);
            //展示图片
            dsBridge.register('setImg', function (img) {
                if(imgType == 1){
                    //资质证书
                    var htmlStr = '<img class="ser-img" src="'+showSmallImg(img)+'" alt="" onclick="deleteImg(this)" imgId="'+img+'">';
                    $("#selectCredentialImg").before(htmlStr);
                    if ($("img.ser-img").length > maxImgNum) {
                        $("#selectCredentialImg").hide();
                    } else {
                        $("#selectCredentialImg").show();
                    }
                }else{
                    //机构logo
                    $("#headPortrait").attr("src",showSmallImg(img)).attr("imgId",img);
                }
            })
            
            dsBridge.register('showTrainType', function () {
                showTrainType();
            })
        })

        //获取机构信息
        function getDetail(){
            var data = {
                userAccId:getUserId()
            }
            getServerData(url_trainorgmgr_getTrainOrganizationDetails, data); 
        }

        //选择地址
        function showAddress() {
            pickerAddress.show(function (item) {
                provinceCode = emptyShow(item[0].value);
                cityCode = emptyShow(item[1].value);
                countyCode = emptyShow(item[2].value);
                var address = item[0].text + emptyShow(item[1].text) + emptyShow(item[2].text);
                $("#address").text(address);
            });
        }

        //选择擅长培训类型
        function selectTrainType(){
            var orgServiceType = {
                "serviceTypeCodeList":serviceTypeCodeList,
                "serviceTypeNameList":serviceTypeNameList
            }
            localStorage.setItem("orgServiceType",toJson(orgServiceType));
            dsBridge.call("selectTrainType","");
        }

        //展示擅长培训类型
        function showTrainType(){
            var orgServiceType = strToJson(localStorage.getItem("orgServiceType"));
            serviceTypeCodeList = orgServiceType.serviceTypeCodeList;
            serviceTypeNameList = orgServiceType.serviceTypeNameList;
            if(serviceTypeNameList != null && serviceTypeNameList.length > 0){
                $("#serviceTypeNames").text(serviceTypeNameList.join("，"));
            }else{
                $("#serviceTypeNames").text("");
            }
        }

        //选择图片
        function selectImg(type){
            imgType = type;
            dsBridge.call("selectImg","");
        }

        //删除图片
        function deleteImg(obj) {
            layer.open({
                content: '是否删除图片？'
                ,btn: ['删除', '取消']
                ,yes: function(index){
                    $(obj).remove();
                    if ($("img.ser-img").length > maxImgNum) {
                        $("#selectCredentialImg").hide();
                    } else {
                        $("#selectCredentialImg").show();
                    }
                    layer.close(index);
                }
            });
        }

        //保存
        function save(){
            if(isEmpty(provinceCode)){
                showToast("请选择培训地点");
                return;
            }
            if(serviceTypeCodeList == null || serviceTypeCodeList.length == 0){
                showToast("请选择擅长培训类型");
                return;
            }
            //资质证书
            var credentialList = new Array();
            $("img.ser-img[id!='selectCredentialImg']").each(function(index,item){
                credentialList.push($(item).attr("imgId"));
            })
            var data = {
                userAccId:getUserId(),
                headPortrait:$("#headPortrait").attr("imgId"),
                provinceCode:provinceCode,
                cityCode:cityCode,
                countyCode:countyCode,
                addressDetail:$("#addressDetail").val(),
                introduction:$("#introduction").val(),
                serviceTypeCodeList:serviceTypeCodeList,
                credentialList:credentialList
            }
            getServerData(url_trainorgmgr_saveTrainOrgInfo, data); 
        }

        function getServerDataSuccess(url, data) {
            switch (url) {
                case url_trainorgmgr_getTrainOrganizationDetails:
                    data = data.data;
                    var headPortrait = data.headPortrait;
                    if(!isEmpty(headPortrait)){
                        $("#headPortrait").attr("src",showSmallImg(headPortrait)).attr("imgId",headPortrait);
                    }
                    $("#mobilePhone").text(data.mobilePhone);
                    if(!isEmpty(data.establishTime)){
                        $("#establishTime").text(data.establishTime.substring(0,10));
                    }
                    var serviceType = data.serviceType;
                    if(serviceType != null && serviceType.length > 0){
                        $.each(serviceType,function(index,item){
                            serviceTypeCodeList.push(item.code);
                            serviceTypeNameList.push(item.name);
                        })
                        $("#serviceTypeNames").text(serviceTypeNameList.join("，"));
                    }
                    $("#addressDetail").val(emptyShow(data.address));
                    var addressDetail = "";
                    var province = data.province;
                    var city = data.city;
                    var county = data.county;
                    if(province != null){
                        provinceCode = province.provinceCode;
                        addressDetail += province.provinceName;
                    }
                    if(city != null){
                        cityCode = city.cityCode;
                        addressDetail += city.cityName;
                    }
                    if(county != null){
                        countyCode = county.countyCode;
                        addressDetail += county.countyName;
                    }
                    $("#address").html(addressDetail);
                    $("#introduction").val(data.introduction);
                    //资质证书
                    var credentials = data.credentials;
                    var h5 = '';
                    if(credentials != null && credentials.length > 0){
                        $.each(credentials,function(index,item){
                            h5 += '<img class="ser-img" src="'+showSmallImg(item.pictureVideoId)+'" alt="" onclick="deleteImg(this)" imgId="'+item.pictureVideoId+'">';
                        })
                    }
                    $("#selectCredentialImg").before(h5);
                    if ($("img.ser-img").length > maxImgNum) {
                        $("#selectCredentialImg").hide();
                    } else {
                        $("#selectCredentialImg").show();
                    }
                    break;
                case url_trainorgmgr_saveTrainOrgInfo:
                    //保存
                    //信息框
                    layer.open({
                        content: "保存成功",
                        btn: '确定',
                        shadeClose:false,
                        yes: function (index) {
                            layer.close(index);
                            dsBridge.call("saveClose","");
                        }
                    });
                    break;
            }
        }
    </script>
</body>

</html>